/*
 * OverridableOptions.java
 *
 * Created on Nov 5, 2011, 2:40:52 PM
 */
package com.munian.ivy.module.ui.options;

import com.munian.ivy.module.options.IvyRetrieveSettings;
import com.munian.ivy.module.util.Utilities;
import java.util.Collection;

/**
 *
 * @author raymond
 */
public class OverridableOptions extends javax.swing.JPanel {
    /** Creates new form OverridableOptions */
    public OverridableOptions() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    public void loadPanel(IvyRetrieveSettings settings){
        
        ivyJarTypesText.setText(Utilities.collectionToString(settings.getJarTypes()));
        ivySourceTypesText.setText(Utilities.collectionToString(settings.getSourceTypes()));
        ivySourceSuffixesText.setText(Utilities.collectionToString(settings.getSourceSuffixes()));
        ivyJavadocTypesText.setText(Utilities.collectionToString(settings.getJavadocTypes()));
        ivyJavadocSuffixesText.setText(Utilities.collectionToString(settings.getJavadocSuffixes()));
    }
    public boolean readPanel(IvyRetrieveSettings settings){
        
        boolean retVal = true;
        Collection<String> newVals = Utilities.stringToCollection(ivyJarTypesText.getText());
        retVal &= Utilities.collectionsMatch(newVals, settings.getJarTypes());
        settings.getJarTypes().clear();
        settings.getJarTypes().addAll(newVals);
        
        newVals = Utilities.stringToCollection(ivySourceTypesText.getText());
        retVal &= Utilities.collectionsMatch(newVals,settings.getSourceTypes());
        settings.getSourceTypes().clear();
        settings.getSourceTypes().addAll(newVals);
        
        newVals = Utilities.stringToCollection(ivySourceSuffixesText.getText());
        retVal &= Utilities.collectionsMatch(newVals, settings.getSourceSuffixes());
        settings.getSourceSuffixes().clear();
        settings.getSourceSuffixes().addAll(newVals);
        
        newVals = Utilities.stringToCollection(ivyJavadocTypesText.getText());
        retVal &= Utilities.collectionsMatch(newVals, settings.getJavadocTypes());
        settings.getJavadocTypes().clear();
        settings.getJavadocTypes().addAll(newVals);
        
        newVals = Utilities.stringToCollection(ivyJavadocSuffixesText.getText());
        retVal &= Utilities.collectionsMatch(newVals, settings.getJavadocSuffixes());
        settings.getJavadocSuffixes().clear();
        settings.getJavadocSuffixes().addAll(newVals);
        return !retVal;
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        ivyJarTypesLabel = new javax.swing.JLabel();
        ivyJarTypesText = new javax.swing.JTextField();
        ivySourceTypesLabel = new javax.swing.JLabel();
        ivySourceTypesText = new javax.swing.JTextField();
        ivySourceSuffixesLabel = new javax.swing.JLabel();
        ivySourceSuffixesText = new javax.swing.JTextField();
        ivyJavadocTypesLabel = new javax.swing.JLabel();
        ivyJavadocTypesText = new javax.swing.JTextField();
        ivyJavadocSuffixesLabel = new javax.swing.JLabel();
        ivyJavadocSuffixesText = new javax.swing.JTextField();

        setLayout(new java.awt.GridBagLayout());

        ivyJarTypesLabel.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivyJarTypesLabel.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        add(ivyJarTypesLabel, gridBagConstraints);

        ivyJarTypesText.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivyJarTypesText.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 3.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        add(ivyJarTypesText, gridBagConstraints);

        ivySourceTypesLabel.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivySourceTypesLabel.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        add(ivySourceTypesLabel, gridBagConstraints);

        ivySourceTypesText.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivySourceTypesText.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 3.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        add(ivySourceTypesText, gridBagConstraints);

        ivySourceSuffixesLabel.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivySourceSuffixesLabel.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        add(ivySourceSuffixesLabel, gridBagConstraints);

        ivySourceSuffixesText.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivySourceSuffixesText.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 3.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        add(ivySourceSuffixesText, gridBagConstraints);

        ivyJavadocTypesLabel.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivyJavadocTypesLabel.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        add(ivyJavadocTypesLabel, gridBagConstraints);

        ivyJavadocTypesText.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivyJavadocTypesText.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 3.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        add(ivyJavadocTypesText, gridBagConstraints);

        ivyJavadocSuffixesLabel.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivyJavadocSuffixesLabel.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        add(ivyJavadocSuffixesLabel, gridBagConstraints);

        ivyJavadocSuffixesText.setText(org.openide.util.NbBundle.getMessage(OverridableOptions.class, "OverridableOptions.ivyJavadocSuffixesText.text")); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 3.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        add(ivyJavadocSuffixesText, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ivyJarTypesLabel;
    private javax.swing.JTextField ivyJarTypesText;
    private javax.swing.JLabel ivyJavadocSuffixesLabel;
    private javax.swing.JTextField ivyJavadocSuffixesText;
    private javax.swing.JLabel ivyJavadocTypesLabel;
    private javax.swing.JTextField ivyJavadocTypesText;
    private javax.swing.JLabel ivySourceSuffixesLabel;
    private javax.swing.JTextField ivySourceSuffixesText;
    private javax.swing.JLabel ivySourceTypesLabel;
    private javax.swing.JTextField ivySourceTypesText;
    // End of variables declaration//GEN-END:variables
}
